import { bunPluginPino } from 'bun-plugin-pino';

try {
  const build = await Bun.build({
    entrypoints: ['./src/index.ts'],
    outdir: './dist',
    target: 'bun',
    format: 'esm',
    splitting: true,
    minify: {
      syntax: true,
      whitespace: true,
    },
    plugins: [
      bunPluginPino({
        transports: ['pino-pretty', 'pino-opentelemetry-transport'],
        // logging?: "default" | "plain" | "quiet"
      }),
    ],
  });

  for (const output of build.outputs) {
    console.log(output);
  }

  if (build.logs.length > 0) {
    console.warn('Build succeeded with warnings:');
    for (const message of build.logs) {
      // Bun will pretty print the message object
      console.warn(message);
    }
  }
} catch (e) {
  // TypeScript does not allow annotations on the catch clause
  const error = e as AggregateError;
  console.error('Build Failed');

  // Example: Using the built-in formatter
  console.error(error);
}
